package com.lanou.zakerproject.disport;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.lanou.zakerproject.R;
import com.lanou.zakerproject.base.VolleySingleton;

/**
 * Created by dllo on 16/1/20.
 */
public class DisportGroupAdapter extends BaseAdapter {
    private Context context;
    private DisportGroupData disportGroupData;

    public DisportGroupAdapter(Context context, DisportGroupData disportGroupData) {
        this.context = context;
        this.disportGroupData = disportGroupData;
    }

    @Override
    public int getCount() {
        return disportGroupData.getData().getItems().size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder myViewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_hotspot_ex_child, parent, false);
            myViewHolder = new MyViewHolder(convertView);
            convertView.setTag(myViewHolder);
        } else {
            myViewHolder = (MyViewHolder) convertView.getTag();
        }
        ImageLoader.ImageListener listener = ImageLoader.getImageListener(myViewHolder.item_dis_group_img, R.mipmap.iconfont_picpng, R.mipmap.default_img_nonet);
        VolleySingleton.getImageLoader().get(disportGroupData.getData().getItems().get(position).getPic().getUrl(), listener);
        myViewHolder.item_dis_group_title.setText(disportGroupData.getData().getItems().get(position).getTitle());
        myViewHolder.item_dis_group_subTitle.setText(disportGroupData.getData().getItems().get(position).getContent());
        return convertView;
    }

    class MyViewHolder {
        private ImageView item_dis_group_img;
        private TextView item_dis_group_title, item_dis_group_subTitle;

        public MyViewHolder(View view) {
            item_dis_group_img = (ImageView) view.findViewById(R.id.item_hotspot_ex_child_img);
            item_dis_group_title = (TextView) view.findViewById(R.id.item_hotspot_ex_child_title);
            item_dis_group_subTitle = (TextView) view.findViewById(R.id.item_hotspot_ex_child_subtitle);
        }
    }
}
